package org.zero.concurrency.demo.example.singleton;

import org.zero.concurrency.demo.annotations.Recommend;
import org.zero.concurrency.demo.annotations.ThreadSafe;

/**
 * 使用静态内部类实现的单例模式-线程安全
 * 实例在第一次使用的时候创建
 *
 * @author 01
 */
@Recommend
@ThreadSafe
public class SingletonExample8 {
    /**
     * 私有构造函数
     */
    private SingletonExample8() {
    }

    /**
     * 静态工厂方法-获取实例
     *
     * @return instance
     */
    public static SingletonExample8 getInstance() {
        return LazyHolder.INSTANCE;
    }

    /**
     * 用静态内部类创建单例对象
     */
    private static class LazyHolder {
        private static final SingletonExample8 INSTANCE = new SingletonExample8();
    }
}
